import yaml
from baseTools.myLogger import logger

def read_yaml(file, key_word=''):
    logger.info("读取测试用例数据，读取文件：{}，关键字：{}".format(file, key_word))
    try:
        with open(file, 'r', encoding='utf-8') as f:
            values = yaml.safe_load(f)
            if key_word:
                new_values = []
                for value in values:
                    if key_word == value.get("key_word"):
                        new_values.append(value)
                return new_values
            else:
                return values
    except Exception as e:
        logger.warning(e)
        raise Exception("测试用例数据读取失败！")
